//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using System.Text;
using Shp.Runtime.Contract;
using System.ServiceModel;
using System.IO;

namespace LitwareHR.Portfolio.Gateways
{
    static public class WorkflowGateway
    {
        static public void AddWorkflowDef(string name, string xoml)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                channel.AddWorkflowDef(name, xoml);
            }
        }

        static public string GetRuleSetDef()
        {
            using (SecureChannel channel = new SecureChannel())
            {
                return channel.GetRuleSetDef();
            }
        }

        static public void UpdateWorkflowDef(Guid workflowId, string name, string xoml)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                channel.UpdateWorkflowDef(workflowId, name, xoml);
            }
        }

        static public WorkflowDto GetWorkflowDef(Guid workflowId)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                return channel.GetWorkflowDef(workflowId);
            }
        }

        static public Dictionary<Guid, string> GetWorkflowDefList()
        {
            using (SecureChannel channel = new SecureChannel())
            {
                return channel.GetWorkflowDefList();                
            }
        }

        static public void UpdateRuleSetDef(string markup)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                channel.UpdateRuleSetDef(markup);
            }
        }
        

        private class SecureChannel : ClientBase<IWorkflowSC>, IWorkflowSC
        {
            #region IWorkflowSC Members

            public void AddWorkflowDef(string name, string xoml)
            {
                base.Channel.AddWorkflowDef(name, xoml);
            }

            public void UpdateWorkflowDef(Guid workflowId, string name, string xoml)
            {
                base.Channel.UpdateWorkflowDef(workflowId, name, xoml);
            }

            public WorkflowDto GetWorkflowDef(Guid workflowId)
            {
                return base.Channel.GetWorkflowDef(workflowId);
            }

            public Dictionary<Guid, string> GetWorkflowDefList()
            {
                return base.Channel.GetWorkflowDefList();
            }

            public string GetRuleSetDef()
            {
                return base.Channel.GetRuleSetDef();
            }

            public void UpdateRuleSetDef(string markup)
            {
                base.Channel.UpdateRuleSetDef(markup);
            }

            #endregion
        }
    }
}
